"""
类由元类创建而来
元类的父类是type
下面介绍元类写法与相关
"""

"""
用法一， 为所有类添加一个属性



class MetaC(type):  # 元类统一继承自type
    def __new__(mcls, name, bases, attrs):
        attrs["author"] = "zouMa"
        return super().__new__(mcls, name, bases, attrs)


class C(metaclass=MetaC):  # metaclass=继承的元类对象
    pass


c = C()
print(c.author)
"""
"""
用法二，限制类的属性
如果想修改实例化时的属性修改__call__()即可



class MetaC(type):
    def __new__(mcls, name, bases, attrs):
        if not name.istitle():
            raise TypeError("应以大写开头")
        return super.__new__(mcls, name, bases, attrs)


class c(metaclass=MetaC):
    pass


c1 = c()
"""